package com.cci.kangdao.service.impl;

import java.util.List;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.dao.ServicesChannelsDao;
import com.cci.kangdao.dao.model.CompanyT;
import com.cci.kangdao.service.ServicesChannelsService;
import com.cci.kangdao.utilTool.ParameterTool;

@Service("ServicesChannelsService")
public class ServicesChannelsImpl implements ServicesChannelsService{
	
	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private ServicesChannelsDao servicesChannelsDao;
	
	public ModelAndView getServicesChannels(Map<String, Object> map) {
		try{
			HttpServletResponse response = (HttpServletResponse)map.get("response");
			HttpServletRequest request = (HttpServletRequest)map.get("request");
			JSONObject obj = new JSONObject();
			//获取cci和jv所有的服务渠道
			List<CompanyT> servicesChannelsList = servicesChannelsDao.getServicesChannels();
			JSONArray jsonArray = new JSONArray();
			JSONObject content;
			if(servicesChannelsList!=null){
				for(CompanyT companyT:servicesChannelsList){
					content =new JSONObject();
					content.put("id", companyT.getId());
					content.put("CompanyName", companyT.getAbbreviation());
					content.put("IsOnline", companyT.getIsOnline());
					content.put("CompanyNo", companyT.getCompanyNo());
					jsonArray.put(content);
				}
			}
			
			obj.put("status", 0);
			obj.put("msg", "");
			obj.put("data", new JSONObject().put("companyTList", jsonArray));
			ParameterTool.writeResponse(response, obj.toString());	
		} catch(Exception e) {
			log.error(e.getMessage(),e);
		}
		return null;
	}


}
